const query = require("../libs/db/MySQL");

var MusicSQL = require('../libs/db/MusicSQL');

/**
 * 音乐模型
 */
class Music {

    /**
     * 构造音乐对象
     * @param  {string} name     歌曲名
     * @param  {string} artist   艺术家
     * @param  {number} duration 时长
     * @param  {string} music    歌曲文件名
     * @param  {string} poster   海报文件名
     * @param  {string} lyric    歌词文件名
     * @return {Music}           音乐对象
     */
    constructor(name, artist, duration, music, poster, lyric) {
        this.name = name
        this.artist = artist
        this.duration = duration
        this.music = music
        this.poster = poster
        this.lyric = lyric
    }

    static find() {
        let params = [

        ]
        query(MusicSQL.queryAll, params, function(err, rows, fields) {
            if (err) throw err


            return rows;
            //do something
        });

    }

    static findOne(id) {
        params = [
            id
        ]
        query(MusicSQL.queryAll, params, function(err, vals, fields) {
            if (err) throw err


            //do something
        });

    }

    save() {
        let params = [
            this.name,
            this.artist,
            this.duration,
            this.music,
            this.poster,
            this.lyric
        ]

        query(MusicSQL.insert, params, function(err, vals, fields) {
            if (err) throw err


            //do something
        });

    }
    delete(id) {
        params = [
            id
        ]
        query(MusicSQL.delete, params, function(err, vals, fields) {
            if (err) throw err


            //do something
        });
    }

    update(id) {
        let params = [
            this.name,
            this.artist,
            this.duration,
            this.music,
            this.poster,
            this.lyric,
            id
        ]

        query(MusicSQL.update, params, function(err, vals, fields) {
            if (err) throw err


            //do something
        });
    }
}


module.exports = Music